

<!DOCTYPE html>
<html lang="zh-CN" color-mode=light>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>常用代码 - 唱跳rap</title>
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="google" content="notranslate" />
  
  <meta name="description" content="代码设置tomcat虚拟目录
1&gt;server....">
  <meta name="author" content="东子">
  <link rel="icon" href="/images/icons/icon-29.png" type="image/png" sizes="16x16">
  <link rel="icon" href="/images/icons/icon-29@2x.png" type="image/png" sizes="32x32">
  <link rel="apple-touch-icon" href="/images/icons/icon-1024.png" sizes="180x180">
  <meta rel="mask-icon" href="/images/icons/stun-logo.svg" color="#333333">
  
    <meta rel="msapplication-TileImage" content="/images/icons/icon-1024.png">
    <meta rel="msapplication-TileColor" content="#000000">
  

  
<link rel="stylesheet" href="/css/style.css">


  
    
<link rel="stylesheet" href="https://at.alicdn.com/t/font_1445822_p6ry5n7lrr.css">

  

  
    
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css">

  

  
    
      
        
        
<link rel="stylesheet" href="https://cdn.bootcss.com/highlight.js/9.18.1/styles/xcode.min.css" name="highlight-style" mode="light">

      
        
        
<link rel="stylesheet" href="https://cdn.bootcss.com/highlight.js/9.18.1/styles/solarized-dark.min.css" name="highlight-style" mode="dark">

      
  

  <script>
    var CONFIG = window.CONFIG || {};
    var ZHAOO = window.ZHAOO || {};
    CONFIG = {
      isHome: false,
      fancybox: true,
      pjax: false,
      loading: {
        gif: '',
        lottie: ''
      },
      lazyload: {
        enable: true,
        only_post: 'false',
        loading: {
          gif: '',
          lottie: ''
        }
      },
      donate: {
        enable: false,
        alipay: 'https://pic.izhaoo.com/alipay.jpg',
        wechat: 'https://pic.izhaoo.com/wechat.jpg'
      },
      galleries: {
        enable: false
      },
      fab: {
        enable: true,
        always_show: false
      },
      carrier: {
        enable: true
      },
      daovoice: {
        enable: false
      },
      preview: {
        background: {
          default: '',
          api: 'https://api.paugram.com/bing/'
        },
        motto: {
          default: '我在开了灯的床头下，想问问自己的心啊。',
          typing: true,
          api: 'https://v2.jinrishici.com/one.json',
          data_contents: '["data","content"]'
        },
      },
      qrcode: {
        enable: true,
        type: 'url',
        image: 'https://pic.izhaoo.com/weapp-code.jpg',
      },
      toc: {
        enable: true
      },
      scrollbar: {
        type: 'default'
      },
      notification: {
        enable: false,
        delay: 4500,
        list: '',
        page_white_list: '',
        page_black_list: ''
      },
      search: {
        enable: false,
        path: ''
      }
    }
  </script>

  

  

<meta name="generator" content="Hexo 6.3.0"></head>

<body class="lock-screen">
  <div class="loading" id="loading"></div>
  
    


  <nav class="navbar">
    <div class="left">
      
        <i class="iconfont iconhome j-navbar-back-home"></i>
      
      
        <i class="iconfont iconqrcode j-navbar-qrcode"></i>
      
      
        <i class="iconfont iconmoono" id="color-toggle" color-toggle="light"></i>
      
      
    </div>
    <div class="center">常用代码</div>
    <div class="right">
      <i class="iconfont iconmenu j-navbar-menu"></i>
    </div>
    
      <div id="qrcode-navbar"></div>
    
  </nav>

  
  

<nav class="menu">
  <div class="menu-container">
    <div class="menu-close">
      <i class="iconfont iconbaseline-close-px"></i>
    </div>
    <ul class="menu-content"><li class="menu-item">
        <a href="/ " class="underline "> 首页</a>
      </li><li class="menu-item">
        <a href="/archives/ " class="underline "> 归档</a>
      </li><li class="menu-item">
        <a href="/categories/ " class="underline "> 分类</a>
      </li><li class="menu-item">
        <a href="/about/ " class="underline "> 关于</a>
      </li></ul>
    
      <div class="menu-copyright"><p>Powered by <a target="_blank" href="https://gitee.com/comebackearly">东子</a>  | 爷-青结~~</p></div>
    
  </div>
</nav>
  <main id="main">
  <div class="article-wrap">
    <div class="row container">
      <div class="col-xl-3"></div>
      <div class="col-xl-6"><article class="article">
  <div class="wrap">
    <section class="head">
  <img   class="lazyload" data-original="https://tse3-mm.cn.bing.net/th/id/OIP-C.1aYOQRxCj3YTN-OGmZ9cBAHaDt?pid=ImgDet&rs=1" src=""  draggable="false">
  <div class="head-mask">
    <h1 class="head-title">常用代码</h1>
    <div class="head-info">
      <span class="post-info-item"><i class="iconfont iconcalendar"></i>八月 20, 2018</span>
      
      <span class="post-info-item"><i class="iconfont iconfont-size"></i>40746</span>
    </div>
  </div>
</section>
    <section class="main">
      <section class="content">
        
        <h1 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h1><h2 id="设置tomcat虚拟目录"><a href="#设置tomcat虚拟目录" class="headerlink" title="设置tomcat虚拟目录"></a>设置tomcat虚拟目录</h2><blockquote>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&gt;<span class="keyword">server</span>.servlet.context-<span class="type">path</span>=/dz  </span><br></pre></td></tr></table></figure>
</blockquote>
<h2 id="当结果不为空时候封装为json返回"><a href="#当结果不为空时候封装为json返回" class="headerlink" title="当结果不为空时候封装为json返回"></a>当结果不为空时候封装为json返回</h2><blockquote>
<p>通过在类上加注解，当类内部有字段为空的时候，就不会封装该字段。</p>
</blockquote>
<p><strong>添加依赖</strong></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span> </span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.fasterxml.jackson.core<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span> </span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>jackson-databind<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span> </span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.5.3<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p><strong>添加注解</strong></p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//不为空封装为json返回</span></span><br><span class="line"><span class="meta">@JsonInclude(JsonInclude.Include.NON_NULL)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ResultVo</span> &#123; </span><br><span class="line">	.....</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="快速复制一个文件到另一个文件"><a href="#快速复制一个文件到另一个文件" class="headerlink" title="快速复制一个文件到另一个文件"></a>快速复制一个文件到另一个文件</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> IOException &#123;</span><br><span class="line">    <span class="keyword">try</span> (<span class="type">FileOutputStream</span> <span class="variable">fileOutputStream</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileOutputStream</span>(<span class="string">&quot;test2.txt&quot;</span>)</span><br><span class="line">         ;</span><br><span class="line">         <span class="type">FileInputStream</span> <span class="variable">fileInputStream</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileInputStream</span>(<span class="string">&quot;test.txt&quot;</span>)</span><br><span class="line">    )&#123;</span><br><span class="line">        <span class="type">FileChannel</span> <span class="variable">channel</span> <span class="operator">=</span> fileInputStream.getChannel();</span><br><span class="line">        channel.transferTo(<span class="number">0</span>,channel.size(),fileOutputStream.getChannel());</span><br><span class="line">    &#125;<span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">        System.out.println(e.getMessage());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="Blog"><a href="#Blog" class="headerlink" title="Blog"></a>Blog</h1><h2 id="优雅代码——-构建目录树（用动态菜单举例子）"><a href="#优雅代码——-构建目录树（用动态菜单举例子）" class="headerlink" title="优雅代码——-构建目录树（用动态菜单举例子）"></a>优雅代码——-构建目录树（用动态菜单举例子）</h2><pre><code>@Override
public List&lt;Menu&gt; selectRouterMenuTreeByUserId(Long userId) &#123;
    MenuMapper menuMapper = getBaseMapper();
    List&lt;Menu&gt; menus = null;
    //判断是否是管理员
    if(SecurityUtils.isAdmin())&#123;
    //如果是 获取所有符合要求的Menu
        menus = menuMapper.selectAllRouterMenu();
    &#125;else&#123;
    //否则  获取当前用户所具有的Menu
        menus = menuMapper.selectRouterMenuTreeByUserId(userId);
    &#125;
   //构建tree
    //先找出第一层的菜单  然后去找他们的子菜单设置到children属性中
    List&lt;Menu&gt; menuTree = builderMenuTree(menus,0L);
    return menuTree;
&#125;

private List&lt;Menu&gt; builderMenuTree(List&lt;Menu&gt; menus, Long parentId) &#123;
    List&lt;Menu&gt; menuTree = menus.stream()
            .filter(menu -&gt; menu.getParentId().equals(parentId))
            .map(menu -&gt; menu.setChildren(getChildren(menu, menus)))
            .collect(Collectors.toList());
    return menuTree;
&#125;

/**
 * 获取存入参数的 子Menu集合
 * @param menu
 * @param menus
 * @return
 */
private List&lt;Menu&gt; getChildren(Menu menu, List&lt;Menu&gt; menus) &#123;
    List&lt;Menu&gt; childrenList = menus.stream()
            .filter(m -&gt; m.getParentId().equals(menu.getId()))
            .map(m-&gt;m.setChildren(getChildren(m,menus)))
            .collect(Collectors.toList());
    return childrenList;
&#125;
</code></pre>
<h2 id="PageVO"><a href="#PageVO" class="headerlink" title="PageVO"></a>PageVO</h2><blockquote>
<p> pageVO这个我们不使用mybatisplus 提供的那个page对象，自己封装一下，然后进行拷贝</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> lombok.AllArgsConstructor;</span><br><span class="line"><span class="keyword">import</span> lombok.Data;</span><br><span class="line"><span class="keyword">import</span> lombok.NoArgsConstructor;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@NoArgsConstructor</span></span><br><span class="line"><span class="meta">@AllArgsConstructor</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">PageVo</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> List rows;</span><br><span class="line">    <span class="keyword">private</span> Long total;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="测试神器"><a href="#测试神器" class="headerlink" title="测试神器"></a>测试神器</h2><p><img   class="lazyload" data-original="https://gitee.com/yuan-wendong/picture-bed/raw/master/image-20230309222137008.png" src=""  alt="image-20230309222137008"></p>
<h2 id="aop注解日志"><a href="#aop注解日志" class="headerlink" title="aop注解日志"></a>aop注解日志</h2><p>首先有一个注解</p>
<figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">@Retention</span>(RetentionPolicy.RUNTIME)</span><br><span class="line"><span class="variable">@Target</span>(ElementType.METHOD)</span><br><span class="line">public <span class="variable">@interface</span> SystemLog &#123;</span><br><span class="line">    <span class="selector-tag">String</span> <span class="selector-tag">businessName</span>();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>aop代理注解内容增强(spring-aop的依赖)</p>
<figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line">package com.sangeng.aspect;</span><br><span class="line"></span><br><span class="line">import com.alibaba.fastjson.JSON;</span><br><span class="line">import com.sangeng.annotation.SystemLog;</span><br><span class="line">import lombok.extern.slf4j.Slf4j;</span><br><span class="line">import org.aspectj.lang.ProceedingJoinPoint;</span><br><span class="line">import org.aspectj.lang.annotation.Around;</span><br><span class="line">import org.aspectj.lang.annotation.Aspect;</span><br><span class="line">import org.aspectj.lang.annotation.Pointcut;</span><br><span class="line">import org.aspectj.lang.reflect.MethodSignature;</span><br><span class="line">import org.springframework.stereotype.Component;</span><br><span class="line">import org.springframework.web.context.request.RequestAttributes;</span><br><span class="line">import org.springframework.web.context.request.RequestContextHolder;</span><br><span class="line">import org.springframework.web.context.request.ServletRequestAttributes;</span><br><span class="line"></span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line"></span><br><span class="line">@Component</span><br><span class="line">@Aspect</span><br><span class="line">@Slf4j</span><br><span class="line">public <span class="keyword">class</span> LogAspect &#123;</span><br><span class="line"></span><br><span class="line">    @<span class="constructor">Pointcut(<span class="string">&quot;@annotation(com.sangeng.annotation.SystemLog)&quot;</span>)</span></span><br><span class="line">    public void pt<span class="literal">()</span>&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @<span class="constructor">Around(<span class="string">&quot;pt()&quot;</span>)</span></span><br><span class="line">    public Object print<span class="constructor">Log(ProceedingJoinPoint <span class="params">joinPoint</span>)</span> throws Throwable &#123;</span><br><span class="line"></span><br><span class="line">        Object ret;</span><br><span class="line">        <span class="comment">//这里的是try finally的操作，没处理，交给全局处理</span></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">//处理之前的增强需要jointPoint</span></span><br><span class="line">            handle<span class="constructor">Before(<span class="params">joinPoint</span>)</span>;</span><br><span class="line">            <span class="comment">//相当于目标方法的执行</span></span><br><span class="line">            ret = joinPoint.proceed<span class="literal">()</span>;</span><br><span class="line">            handle<span class="constructor">After(<span class="params">ret</span>)</span>;</span><br><span class="line">        &#125; finally &#123;</span><br><span class="line">            <span class="comment">// 结束后换行System.lineSeparator()</span></span><br><span class="line">            log.info(<span class="string">&quot;=======End=======&quot;</span> + <span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>line<span class="constructor">Separator()</span>);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        return ret;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> void handle<span class="constructor">After(Object <span class="params">ret</span>)</span> &#123;</span><br><span class="line">        <span class="comment">// 打印出参</span></span><br><span class="line">        log.info(<span class="string">&quot;Response       : &#123;&#125;&quot;</span>, <span class="module-access"><span class="module"><span class="identifier">JSON</span>.</span></span><span class="keyword">to</span><span class="constructor">JSONString(<span class="params">ret</span>)</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> void handle<span class="constructor">Before(ProceedingJoinPoint <span class="params">joinPoint</span>)</span> &#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//用threadlocal中的共享变量</span></span><br><span class="line">        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) <span class="module-access"><span class="module"><span class="identifier">RequestContextHolder</span>.</span></span>get<span class="constructor">RequestAttributes()</span>;</span><br><span class="line">        HttpServletRequest request = requestAttributes.get<span class="constructor">Request()</span>;</span><br><span class="line">        <span class="comment">//获取被增强方法上的注解对象 jointPoint</span></span><br><span class="line">        SystemLog systemLog = get<span class="constructor">SystemLog(<span class="params">joinPoint</span>)</span>;</span><br><span class="line">        log.info(<span class="string">&quot;=======Start=======&quot;</span>);</span><br><span class="line">        <span class="comment">// 打印请求 URL</span></span><br><span class="line">        log.info(<span class="string">&quot;URL            : &#123;&#125;&quot;</span>,request.get<span class="constructor">RequestURL()</span>);</span><br><span class="line">        <span class="comment">// 打印描述信息</span></span><br><span class="line">        log.info(<span class="string">&quot;BusinessName   : &#123;&#125;&quot;</span>,systemLog.business<span class="constructor">Name()</span>);</span><br><span class="line">        <span class="comment">// 打印 Http method</span></span><br><span class="line">        log.info(<span class="string">&quot;HTTP Method    : &#123;&#125;&quot;</span>,request.get<span class="constructor">Method()</span>);</span><br><span class="line">        <span class="comment">// 打印调用 controller 的全路径以及执行方法</span></span><br><span class="line">        log.info(<span class="string">&quot;Class Method   : &#123;&#125;.&#123;&#125;&quot;</span>,joinPoint.get<span class="constructor">Signature()</span>.get<span class="constructor">DeclaringTypeName()</span>,((MethodSignature) joinPoint.get<span class="constructor">Signature()</span>).get<span class="constructor">Name()</span>);</span><br><span class="line">        <span class="comment">// 打印请求的 IP</span></span><br><span class="line">        log.info(<span class="string">&quot;IP             : &#123;&#125;&quot;</span>,request.get<span class="constructor">RemoteHost()</span>);</span><br><span class="line">        <span class="comment">// 打印请求入参</span></span><br><span class="line">        log.info(<span class="string">&quot;Request Args   : &#123;&#125;&quot;</span>, <span class="module-access"><span class="module"><span class="identifier">JSON</span>.</span></span><span class="keyword">to</span><span class="constructor">JSONString(<span class="params">joinPoint</span>.<span class="params">getArgs</span>()</span>) );</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> SystemLog get<span class="constructor">SystemLog(ProceedingJoinPoint <span class="params">joinPoint</span>)</span> &#123;</span><br><span class="line">        <span class="comment">//这个签名信息获取</span></span><br><span class="line">        MethodSignature methodSignature = (MethodSignature) joinPoint.get<span class="constructor">Signature()</span>;</span><br><span class="line">        SystemLog systemLog = methodSignature.get<span class="constructor">Method()</span>.get<span class="constructor">Annotation(SystemLog.<span class="params">class</span>)</span>;</span><br><span class="line">        return systemLog;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>相关方法上添加注解实现日志记录</p>
<p><img   class="lazyload" data-original="https://gitee.com/yuan-wendong/picture-bed/raw/master/image-20230317140536044.png" src=""  alt="image-20230317140536044"></p>
<h1 id="开发常用功能"><a href="#开发常用功能" class="headerlink" title="开发常用功能"></a>开发常用功能</h1><h2 id="SpringBoot自定义注解拦截权限"><a href="#SpringBoot自定义注解拦截权限" class="headerlink" title="SpringBoot自定义注解拦截权限"></a>SpringBoot自定义注解拦截权限</h2><h3 id="自定义注解"><a href="#自定义注解" class="headerlink" title="自定义注解"></a>自定义注解</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.lang.annotation.*;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Target(&#123;ElementType.METHOD&#125;)</span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.RUNTIME)</span></span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> AuthAccess &#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="添加一个拦截器"><a href="#添加一个拦截器" class="headerlink" title="添加一个拦截器"></a>添加一个拦截器</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cn.hutool.core.util.StrUtil;</span><br><span class="line"><span class="keyword">import</span> com.auth0.jwt.JWT;</span><br><span class="line"><span class="keyword">import</span> com.auth0.jwt.JWTVerifier;</span><br><span class="line"><span class="keyword">import</span> com.auth0.jwt.algorithms.Algorithm;</span><br><span class="line"><span class="keyword">import</span> com.auth0.jwt.exceptions.JWTDecodeException;</span><br><span class="line"><span class="keyword">import</span> com.auth0.jwt.exceptions.JWTVerificationException;</span><br><span class="line"><span class="keyword">import</span> com.qingge.springboot.common.Constants;</span><br><span class="line"><span class="keyword">import</span> com.qingge.springboot.config.AuthAccess;</span><br><span class="line"><span class="keyword">import</span> com.qingge.springboot.entity.User;</span><br><span class="line"><span class="keyword">import</span> com.qingge.springboot.exception.ServiceException;</span><br><span class="line"><span class="keyword">import</span> com.qingge.springboot.service.IUserService;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.method.HandlerMethod;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.servlet.HandlerInterceptor;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">JwtInterceptor</span> <span class="keyword">implements</span> <span class="title class_">HandlerInterceptor</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> IUserService userService;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">preHandle</span><span class="params">(HttpServletRequest request, HttpServletResponse response, Object handler)</span> &#123;</span><br><span class="line">        <span class="type">String</span> <span class="variable">token</span> <span class="operator">=</span> request.getHeader(<span class="string">&quot;token&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 如果不是映射到方法直接通过</span></span><br><span class="line">        <span class="keyword">if</span>(!(handler <span class="keyword">instanceof</span> HandlerMethod))&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="type">HandlerMethod</span> <span class="variable">h</span> <span class="operator">=</span> (HandlerMethod) handler;</span><br><span class="line">            <span class="type">AuthAccess</span> <span class="variable">authAccess</span> <span class="operator">=</span> h.getMethodAnnotation(AuthAccess.class);</span><br><span class="line">            <span class="keyword">if</span> (authAccess != <span class="literal">null</span>) &#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 执行认证</span></span><br><span class="line">        <span class="keyword">if</span> (StrUtil.isBlank(token)) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">ServiceException</span>(Constants.CODE_401, <span class="string">&quot;无token，请重新登录&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 获取 token 中的 user id</span></span><br><span class="line">        String userId;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            userId = JWT.decode(token).getAudience().get(<span class="number">0</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (JWTDecodeException j) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">ServiceException</span>(Constants.CODE_401, <span class="string">&quot;token验证失败，请重新登录&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 根据token中的userid查询数据库</span></span><br><span class="line">        <span class="type">User</span> <span class="variable">user</span> <span class="operator">=</span> userService.getById(userId);</span><br><span class="line">        <span class="keyword">if</span> (user == <span class="literal">null</span>) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">ServiceException</span>(Constants.CODE_401, <span class="string">&quot;用户不存在，请重新登录&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 用户密码加签验证 token</span></span><br><span class="line">        <span class="type">JWTVerifier</span> <span class="variable">jwtVerifier</span> <span class="operator">=</span> JWT.require(Algorithm.HMAC256(user.getPassword())).build();</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            jwtVerifier.verify(token); <span class="comment">// 验证token</span></span><br><span class="line">        &#125; <span class="keyword">catch</span> (JWTVerificationException e) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">ServiceException</span>(Constants.CODE_401, <span class="string">&quot;token验证失败，请重新登录&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="在需要的接口上添加注解"><a href="#在需要的接口上添加注解" class="headerlink" title="在需要的接口上添加注解"></a>在需要的接口上添加注解</h3><figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">@AuthAccess</span></span><br><span class="line"><span class="variable">@GetMapping</span>(<span class="string">&quot;/file/front/all&quot;</span>)</span><br><span class="line">public Result <span class="built_in">frontAll</span>()&#123;</span><br><span class="line">......</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="批量修改文件后缀"><a href="#批量修改文件后缀" class="headerlink" title="批量修改文件后缀"></a>批量修改文件后缀</h2><h3 id="效果"><a href="#效果" class="headerlink" title="效果"></a>效果</h3><p><img   class="lazyload" data-original="C:/Users/hasee/AppData/Roaming/Typora/typora-user-images/image-20221022170646667.png" src=""  alt="image-20221022170646667"></p>
<p><img   class="lazyload" data-original="https://pic1.imgdb.cn/item/6353b38116f2c2beb1a43a95.png" src=""  alt="image-20221022170812418"></p>
<p><img   class="lazyload" data-original="https://pic1.imgdb.cn/item/6353b35d16f2c2beb1a40d50.png" src=""  alt="image-20221022170736093"></p>
<h3 id="代码-1"><a href="#代码-1" class="headerlink" title="代码"></a>代码</h3><figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">package banch;</span><br><span class="line"></span><br><span class="line">import java.io.*;</span><br><span class="line">import java.util.Scanner;</span><br><span class="line"></span><br><span class="line">public <span class="keyword">class</span> Demo &#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 列出一个文件夹下的所有文件以及目录</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public static void main(String<span class="literal">[]</span> args) &#123;</span><br><span class="line">		<span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(<span class="string">&quot;输入要更改文件的路径&quot;</span>);</span><br><span class="line">		Scanner sc = <span class="keyword">new</span> <span class="constructor">Scanner(System.<span class="params">in</span>)</span>;</span><br><span class="line">		File file = <span class="keyword">new</span> <span class="constructor">File(<span class="params">sc</span>.<span class="params">next</span>()</span>);</span><br><span class="line">        show<span class="constructor">List(<span class="params">file</span>)</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> static void show<span class="constructor">List(File <span class="params">file</span>)</span> &#123;</span><br><span class="line"></span><br><span class="line">		<span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(<span class="string">&quot;输入要更替换的字符串(注意特殊字符转义)&quot;</span>);</span><br><span class="line">		Scanner sc = <span class="keyword">new</span> <span class="constructor">Scanner(System.<span class="params">in</span>)</span>;</span><br><span class="line">		String pre = sc.next<span class="literal">()</span>;</span><br><span class="line">		<span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(<span class="string">&quot;输入目标字符串&quot;</span>);</span><br><span class="line">		String tar = sc.next<span class="literal">()</span>;</span><br><span class="line"></span><br><span class="line">        File<span class="literal">[]</span> listFiles = file.<span class="built_in">list</span><span class="constructor">Files()</span>;</span><br><span class="line">        <span class="keyword">for</span> (File listFile : listFiles) &#123;</span><br><span class="line">            <span class="keyword">if</span> (listFile.is<span class="constructor">File()</span>) &#123;</span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line">                    FileReader fr = <span class="keyword">new</span> <span class="constructor">FileReader(<span class="params">listFile</span>)</span>;</span><br><span class="line">                    <span class="built_in">char</span><span class="literal">[]</span> cs = <span class="keyword">new</span> <span class="built_in">char</span><span class="literal">[<span class="number">1024</span>]</span>;</span><br><span class="line">                    <span class="built_in">int</span> len = <span class="number">0</span>;</span><br><span class="line">                    StringBuilder sb = <span class="keyword">new</span> <span class="constructor">StringBuilder()</span>;</span><br><span class="line">                    <span class="keyword">while</span> ((len = fr.read(cs)) != -<span class="number">1</span>) &#123;</span><br><span class="line">                        String s = <span class="keyword">new</span> <span class="constructor">String(<span class="params">cs</span>, 0, <span class="params">len</span>)</span>;</span><br><span class="line">                        sb.append(s);</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    String ss = sb.<span class="keyword">to</span><span class="constructor">String()</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">					String s = ss.replace<span class="constructor">All(<span class="params">pre</span>,<span class="params">tar</span>)</span>;</span><br><span class="line">                    <span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(s);</span><br><span class="line">					fr.close<span class="literal">()</span>;</span><br><span class="line"></span><br><span class="line">					OutputStreamWriter writer = <span class="keyword">new</span> <span class="constructor">OutputStreamWriter(<span class="params">new</span> FileOutputStream(<span class="params">listFile</span>)</span>, <span class="string">&quot;UTF-8&quot;</span>);</span><br><span class="line">                    BufferedWriter bufferedWriter = <span class="keyword">new</span> <span class="constructor">BufferedWriter(<span class="params">writer</span>)</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">                    bufferedWriter.write(s);</span><br><span class="line"></span><br><span class="line">                    bufferedWriter.flush<span class="literal">()</span>;</span><br><span class="line">                    writer.close<span class="literal">()</span>;</span><br><span class="line">                &#125; catch (Exception e) &#123;</span><br><span class="line">                    <span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(<span class="string">&quot;读取文件内容出错&quot;</span>);</span><br><span class="line">                    e.print<span class="constructor">StackTrace()</span>;</span><br><span class="line">                &#125;</span><br><span class="line"></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="java根据实体类生成相应的数据库sql文件"><a href="#java根据实体类生成相应的数据库sql文件" class="headerlink" title="java根据实体类生成相应的数据库sql文件"></a>java根据实体类生成相应的数据库sql文件</h2><figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br></pre></td><td class="code"><pre><span class="line">package com.twophone.untils;</span><br><span class="line"></span><br><span class="line">import javax.xml.bind.annotation.XmlElement;</span><br><span class="line">import java.io.*;</span><br><span class="line">import java.lang.annotation.Annotation;</span><br><span class="line">import java.lang.reflect.Field;</span><br><span class="line">import java.util.Scanner;</span><br><span class="line"></span><br><span class="line">public <span class="keyword">class</span> GenerateSqlFromEntityUtil &#123; </span><br><span class="line">   </span><br><span class="line"></span><br><span class="line">   public static void main(String<span class="literal">[]</span> a) throws ClassNotFoundException &#123;</span><br><span class="line"></span><br><span class="line">      <span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(<span class="string">&quot;输入要更改实体类的路径&quot;</span>);</span><br><span class="line">      Scanner sc = <span class="keyword">new</span> <span class="constructor">Scanner(System.<span class="params">in</span>)</span>;</span><br><span class="line">      File file = <span class="keyword">new</span> <span class="constructor">File(<span class="params">sc</span>.<span class="params">next</span>()</span>);</span><br><span class="line">      <span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(<span class="string">&quot;输入要更改实体类的路径&quot;</span>);</span><br><span class="line">      String classpkg = sc.next<span class="literal">()</span>;</span><br><span class="line">      File<span class="literal">[]</span> listFiles = file.<span class="built_in">list</span><span class="constructor">Files()</span>;</span><br><span class="line">      <span class="keyword">for</span> (File listFile : listFiles) &#123;</span><br><span class="line">         <span class="keyword">if</span> (listFile.is<span class="constructor">File()</span> ) &#123;</span><br><span class="line">            String clsName = listFile.get<span class="constructor">Name()</span>.split(<span class="string">&quot;\\.&quot;</span>)<span class="literal">[<span class="number">0</span>]</span>;</span><br><span class="line">            Class klass = <span class="module-access"><span class="module"><span class="identifier">Class</span>.</span></span><span class="keyword">for</span><span class="constructor">Name(<span class="params">classpkg</span>+<span class="string">&quot;.&quot;</span>+<span class="params">clsName</span>)</span>;</span><br><span class="line"><span class="comment">//             Class klass =User.class;</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">// 生成的sql语句的位置</span></span><br><span class="line">            String outputPath = <span class="string">&quot;D:/gen.sql&quot;</span>;</span><br><span class="line">            generate<span class="constructor">TableSql(<span class="params">klass</span>, <span class="params">outputPath</span>, <span class="params">null</span>)</span>;</span><br><span class="line"></span><br><span class="line">         &#125;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(<span class="string">&quot;生成结束&quot;</span>);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   public static void write<span class="constructor">File(String <span class="params">content</span>, String <span class="params">outputPath</span>)</span> &#123; </span><br><span class="line">   </span><br><span class="line">      File file = <span class="keyword">new</span> <span class="constructor">File(<span class="params">outputPath</span>)</span>;</span><br><span class="line">      <span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(<span class="string">&quot;文件路径: &quot;</span> + file.get<span class="constructor">AbsolutePath()</span>);</span><br><span class="line">      <span class="comment">// 输出文件的路径</span></span><br><span class="line">      <span class="keyword">if</span> (!file.get<span class="constructor">ParentFile()</span>.exists<span class="literal">()</span>) &#123; </span><br><span class="line">   </span><br><span class="line">         file.get<span class="constructor">ParentFile()</span>.mkdirs<span class="literal">()</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      FileOutputStream fos = null;</span><br><span class="line">      OutputStreamWriter osw = null;</span><br><span class="line">      BufferedWriter out = null;</span><br><span class="line"></span><br><span class="line">      <span class="keyword">try</span> &#123; </span><br><span class="line">   </span><br><span class="line"><span class="comment">//       // 如果文件存在，就删除</span></span><br><span class="line"><span class="comment">//       if (file.exists()) &#123;</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">//          file.delete();</span></span><br><span class="line"><span class="comment">//       &#125;</span></span><br><span class="line">         file.create<span class="constructor">NewFile()</span>;</span><br><span class="line">         fos = <span class="keyword">new</span> <span class="constructor">FileOutputStream(<span class="params">file</span>, <span class="params">true</span>)</span>;</span><br><span class="line">         osw = <span class="keyword">new</span> <span class="constructor">OutputStreamWriter(<span class="params">fos</span>)</span>;</span><br><span class="line">         out = <span class="keyword">new</span> <span class="constructor">BufferedWriter(<span class="params">osw</span>)</span>;</span><br><span class="line">         out.write(content);</span><br><span class="line">         <span class="comment">// 清空缓冲流，把缓冲流里的文本数据写入到目标文件里</span></span><br><span class="line">         out.flush<span class="literal">()</span>;</span><br><span class="line">      &#125; catch (FileNotFoundException e) &#123; </span><br><span class="line">   </span><br><span class="line">         e.print<span class="constructor">StackTrace()</span>;</span><br><span class="line">      &#125; catch (IOException e) &#123; </span><br><span class="line">   </span><br><span class="line">         e.print<span class="constructor">StackTrace()</span>;</span><br><span class="line">      &#125; finally &#123; </span><br><span class="line">   </span><br><span class="line">         <span class="keyword">try</span> &#123; </span><br><span class="line">   </span><br><span class="line">            fos.close<span class="literal">()</span>;</span><br><span class="line">         &#125; catch (IOException e) &#123; </span><br><span class="line">   </span><br><span class="line">            e.print<span class="constructor">StackTrace()</span>;</span><br><span class="line">         &#125;</span><br><span class="line"></span><br><span class="line">         <span class="keyword">try</span> &#123; </span><br><span class="line">   </span><br><span class="line">            osw.close<span class="literal">()</span>;</span><br><span class="line">         &#125; catch (IOException e) &#123; </span><br><span class="line">   </span><br><span class="line">            e.print<span class="constructor">StackTrace()</span>;</span><br><span class="line">         &#125;</span><br><span class="line"></span><br><span class="line">         <span class="keyword">try</span> &#123; </span><br><span class="line">   </span><br><span class="line">            out.close<span class="literal">()</span>;</span><br><span class="line">         &#125; catch (IOException e) &#123; </span><br><span class="line">   </span><br><span class="line">            e.print<span class="constructor">StackTrace()</span>;</span><br><span class="line">         &#125;</span><br><span class="line">      &#125;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   public static void generate<span class="constructor">TableSql(Class <span class="params">obj</span>, String <span class="params">outputPath</span>, String <span class="params">tableName</span>)</span> &#123; </span><br><span class="line">   </span><br><span class="line">      <span class="comment">// tableName 如果是 null，就用类名做表名</span></span><br><span class="line">      <span class="keyword">if</span> (tableName<span class="operator"> == </span>null<span class="operator"> || </span>tableName.equals(<span class="string">&quot;&quot;</span>)) &#123; </span><br><span class="line">   </span><br><span class="line">         tableName = obj.get<span class="constructor">Name()</span>;</span><br><span class="line">         tableName = tableName.substring(tableName.last<span class="constructor">IndexOf(<span class="string">&quot;.&quot;</span>)</span> + <span class="number">1</span>);</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="comment">// 表名用大写字母</span></span><br><span class="line">      tableName = tableName.<span class="keyword">to</span><span class="constructor">UpperCase()</span>;</span><br><span class="line"></span><br><span class="line">      Field<span class="literal">[]</span> fields = obj.get<span class="constructor">DeclaredFields()</span>;</span><br><span class="line">      Object param;</span><br><span class="line">      String column;</span><br><span class="line"></span><br><span class="line">      StringBuilder sb = <span class="keyword">new</span> <span class="constructor">StringBuilder()</span>;</span><br><span class="line"></span><br><span class="line">      sb.append(<span class="string">&quot;drop table if exists &quot;</span>).append(tableName).append(<span class="string">&quot;;\r\n&quot;</span>);</span><br><span class="line"></span><br><span class="line">      sb.append(<span class="string">&quot;\r\n&quot;</span>);</span><br><span class="line"></span><br><span class="line">      sb.append(<span class="string">&quot;create table &quot;</span>).append(tableName).append(<span class="string">&quot;(\r\n&quot;</span>);</span><br><span class="line"></span><br><span class="line">      <span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(tableName);</span><br><span class="line"></span><br><span class="line">      boolean firstId = <span class="literal">true</span>;</span><br><span class="line"></span><br><span class="line">      <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i &lt; fields.length; i++) &#123; </span><br><span class="line">   </span><br><span class="line">         Field f = fields<span class="literal">[<span class="identifier">i</span>]</span>;</span><br><span class="line"></span><br><span class="line">         column = f.get<span class="constructor">Name()</span>;</span><br><span class="line"></span><br><span class="line">         <span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(column + <span class="string">&quot;, &quot;</span> + f.get<span class="constructor">Type()</span>.get<span class="constructor">SimpleName()</span>);</span><br><span class="line"></span><br><span class="line">         param = f.get<span class="constructor">Type()</span>;</span><br><span class="line">         sb.append(column); <span class="comment">// 一般第一个是主键</span></span><br><span class="line"></span><br><span class="line">         <span class="keyword">if</span> (param instanceof Integer) &#123; </span><br><span class="line">   </span><br><span class="line">            sb.append(<span class="string">&quot; INTEGER &quot;</span>);</span><br><span class="line">         &#125; <span class="keyword">else</span> &#123; </span><br><span class="line">   </span><br><span class="line">            <span class="comment">// 注意：根据需要，自行修改 varchar 的长度。这里设定为长度等于 50</span></span><br><span class="line">            <span class="built_in">int</span> length = <span class="number">50</span>;</span><br><span class="line">            sb.append(<span class="string">&quot; VARCHAR(&quot;</span> + length + <span class="string">&quot;)&quot;</span>);</span><br><span class="line">         &#125;</span><br><span class="line"></span><br><span class="line">         <span class="keyword">if</span> (firstId<span class="operator"> == </span><span class="literal">true</span>) &#123; </span><br><span class="line">   </span><br><span class="line">            sb.append(<span class="string">&quot; PRIMARY KEY &quot;</span>);</span><br><span class="line">            firstId = <span class="literal">false</span>;</span><br><span class="line">         &#125;</span><br><span class="line"></span><br><span class="line">         <span class="comment">// 获取字段中包含 fieldMeta 的注解</span></span><br><span class="line"></span><br><span class="line">         <span class="comment">// 获取属性的所有注释</span></span><br><span class="line">         Annotation<span class="literal">[]</span> allAnnotations = f.get<span class="constructor">Annotations()</span>;</span><br><span class="line"></span><br><span class="line">         XmlElement xmlElement = null;</span><br><span class="line">         Class annotationType = null;</span><br><span class="line"></span><br><span class="line">         <span class="keyword">for</span> (Annotation an : allAnnotations) &#123; </span><br><span class="line">   </span><br><span class="line">            sb.append(<span class="string">&quot; COMMIT &#x27;&quot;</span>);</span><br><span class="line">            xmlElement = (XmlElement) an;</span><br><span class="line">            annotationType = an.annotation<span class="constructor">Type()</span>;</span><br><span class="line">            param = ((XmlElement) an).name<span class="literal">()</span>;</span><br><span class="line">            <span class="module-access"><span class="module"><span class="identifier">System</span>.</span></span>out.println(<span class="string">&quot;属性 &quot;</span> + f.get<span class="constructor">Name()</span> + <span class="string">&quot; ----- 的注释类型有: &quot;</span> + param);</span><br><span class="line">            sb.append(param).append(<span class="string">&quot;&#x27;&quot;</span>);</span><br><span class="line">         &#125;</span><br><span class="line"></span><br><span class="line">         <span class="keyword">if</span> (i != fields.length - <span class="number">1</span>) &#123; </span><br><span class="line">    <span class="comment">// 最后一个属性后面不加逗号</span></span><br><span class="line">            sb.append(<span class="string">&quot;, &quot;</span>);</span><br><span class="line">         &#125;</span><br><span class="line"></span><br><span class="line">         sb.append(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      String sql = sb.<span class="keyword">to</span><span class="constructor">String()</span>;</span><br><span class="line"></span><br><span class="line">      sql = sb.substring(<span class="number">0</span>, sql.length<span class="literal">()</span> - <span class="number">1</span>) + <span class="string">&quot;\n) &quot;</span> + <span class="string">&quot;ENGINE = INNODB DEFAULT CHARSET = utf8;&quot;</span>;</span><br><span class="line"></span><br><span class="line">      write<span class="constructor">File(<span class="params">sql</span>, <span class="params">outputPath</span>)</span>;</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="java-找出特定后缀文件"><a href="#java-找出特定后缀文件" class="headerlink" title="java 找出特定后缀文件"></a>java 找出特定后缀文件</h2><h3 id="定义过滤器"><a href="#定义过滤器" class="headerlink" title="定义过滤器"></a>定义过滤器</h3><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">FileAccept</span> <span class="keyword">implements</span> <span class="title class_">FilenameFilter</span> &#123;<span class="comment">//FileAccept类实现FilenameFilter接口</span></span><br><span class="line">    <span class="keyword">private</span> <span class="title class_">String</span> extendName;</span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">void</span> <span class="title function_">setExtendName</span>(<span class="params"><span class="built_in">String</span> s</span>) &#123;</span><br><span class="line">        extendName=<span class="string">&quot;.&quot;</span>+s;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">boolean</span> <span class="title function_">accept</span>(<span class="params">File dir, <span class="built_in">String</span> name</span>) &#123; <span class="comment">//重写接口中的方法</span></span><br><span class="line">        <span class="keyword">return</span> name.<span class="title function_">endsWith</span>(extendName);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h3><figure class="highlight wren"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">public</span> <span class="keyword">class</span> <span class="title class_">Example1_2</span> &#123;</span><br><span class="line">    <span class="variable">public</span> <span class="keyword">static</span> <span class="variable">void</span> <span class="title function_">main</span>(<span class="params">String</span>[] <span class="params">args</span>) &#123;</span><br><span class="line">        <span class="title class_">File</span> <span class="variable">dirFile</span> <span class="operator">=</span> <span class="variable">new</span> <span class="title class_">File</span>(<span class="string">&quot;E:<span class="char escape_">\\</span>java<span class="char escape_">\\</span>JavaSeLearn<span class="char escape_">\\</span>第10章<span class="char escape_">\\</span>src<span class="char escape_">\\</span>ioflow<span class="char escape_">\\</span>&quot;</span>);</span><br><span class="line">        <span class="title class_">FileAccept</span> <span class="variable">fileAccept</span> <span class="operator">=</span> <span class="variable">new</span> <span class="title class_">FileAccept</span>();</span><br><span class="line">        <span class="variable">fileAccept</span>.<span class="property">setExtendName</span>(<span class="string">&quot;java&quot;</span>);</span><br><span class="line">        <span class="title class_">String</span> <span class="variable">fileName</span>[] <span class="operator">=</span> <span class="variable">dirFile</span>.<span class="property">list</span>(<span class="variable">fileAccept</span>);</span><br><span class="line">        <span class="keyword">for</span> (<span class="title class_">String</span> <span class="variable">name</span> : <span class="variable">fileName</span>) &#123;</span><br><span class="line">            <span class="title class_">System</span>.<span class="property">out</span>.<span class="property">println</span>(<span class="variable">name</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Java生成压缩包"><a href="#Java生成压缩包" class="headerlink" title="Java生成压缩包"></a>Java生成压缩包</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.io.*;</span><br><span class="line"><span class="keyword">import</span> java.util.zip.ZipEntry;</span><br><span class="line"><span class="keyword">import</span> java.util.zip.ZipOutputStream;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">zipOut</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> IOException &#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//zipOut zipEntry</span></span><br><span class="line">        <span class="type">FileOutputStream</span> <span class="variable">fileOutputStream</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileOutputStream</span>(<span class="string">&quot;D:\\桌面\\GoBackN-master\\11\\1.zip&quot;</span>);</span><br><span class="line">        <span class="type">ZipOutputStream</span> <span class="variable">zipout</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ZipOutputStream</span>(fileOutputStream);</span><br><span class="line">        </span><br><span class="line">        <span class="type">ZipEntry</span> <span class="variable">zipEntry</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ZipEntry</span>(<span class="string">&quot;a.txt&quot;</span>);</span><br><span class="line">        <span class="type">ZipEntry</span> <span class="variable">zipEntry1</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ZipEntry</span>(<span class="string">&quot;b.txt&quot;</span>);</span><br><span class="line">        <span class="type">ZipEntry</span> <span class="variable">zipEntry2</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ZipEntry</span>(<span class="string">&quot;文件夹&quot;</span> + File.separator + <span class="string">&quot;a.txt&quot;</span>);</span><br><span class="line">        </span><br><span class="line">        zipout.putNextEntry(zipEntry);</span><br><span class="line">        zipout.write(<span class="string">&quot;东子a&quot;</span>.getBytes());</span><br><span class="line">        </span><br><span class="line">        zipout.putNextEntry(zipEntry1);</span><br><span class="line">        zipout.write(<span class="string">&quot;东子&quot;</span>.getBytes());</span><br><span class="line"></span><br><span class="line">        zipout.putNextEntry(zipEntry2);</span><br><span class="line">        zipout.write(<span class="string">&quot;东子&quot;</span>.getBytes());</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        zipout.closeEntry();</span><br><span class="line">        zipout.close();</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="SpringBoot导出csv"><a href="#SpringBoot导出csv" class="headerlink" title="SpringBoot导出csv"></a>SpringBoot导出csv</h2><h3 id="加入依赖"><a href="#加入依赖" class="headerlink" title="加入依赖"></a>加入依赖</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>net.sf.supercsv<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>super-csv<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.4.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.google.code.gson<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>gson<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="编写controller"><a href="#编写controller" class="headerlink" title="编写controller"></a>编写controller</h3><figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">@<span class="constructor">GetMapping(<span class="params">value</span> = <span class="string">&quot;mygen&quot;</span>)</span></span><br><span class="line">public void generate<span class="constructor">CSV1(HttpServletResponse <span class="params">response</span>)</span> throws Exception &#123;</span><br><span class="line">    response.set<span class="constructor">ContentType(<span class="string">&quot;application/octet-stream&quot;</span>)</span>;</span><br><span class="line">    response.set<span class="constructor">CharacterEncoding(<span class="string">&quot;GBK&quot;</span>)</span>;</span><br><span class="line">    response.set<span class="constructor">Header(<span class="string">&quot;Content-disposition&quot;</span>, <span class="string">&quot;attachment;filename=user.csv&quot;</span>)</span>;</span><br><span class="line">    csvService.generate<span class="constructor">CSV1(<span class="params">response</span>)</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="编写service"><a href="#编写service" class="headerlink" title="编写service"></a>编写service</h3><figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">@Override</span><br><span class="line">public void generate<span class="constructor">CSV1(HttpServletResponse <span class="params">response</span>)</span> throws IOException, IllegalAccessException &#123;</span><br><span class="line">    Gson gson = <span class="keyword">new</span> <span class="constructor">Gson()</span>;</span><br><span class="line">    ICsvMapWriter csvWriter = <span class="keyword">new</span> <span class="constructor">CsvMapWriter(<span class="params">response</span>.<span class="params">getWriter</span>()</span>, CsvPreference.STANDARD_PREFERENCE);</span><br><span class="line">    <span class="comment">// 获取头部</span></span><br><span class="line">    String<span class="literal">[]</span> headers = generate<span class="constructor">HeadersArray(User.<span class="params">class</span>.<span class="params">getCanonicalName</span>()</span>);</span><br><span class="line">    csvWriter.write<span class="constructor">Header(<span class="params">headers</span>)</span>;</span><br><span class="line"></span><br><span class="line">    SimpleDateFormat smf = <span class="keyword">new</span> <span class="constructor">SimpleDateFormat(<span class="string">&quot;yyyy-MM-dd&quot;</span>)</span>;</span><br><span class="line"></span><br><span class="line">    List&lt;User&gt; users = <span class="keyword">new</span> ArrayList&lt;&gt;<span class="literal">()</span>;</span><br><span class="line">    User user1 = <span class="keyword">new</span> <span class="constructor">User(<span class="string">&quot;张三&quot;</span>, <span class="string">&quot;http:lcoalhost：8080//user.png&quot;</span>, <span class="string">&quot;李四&quot;</span>, <span class="params">new</span> Date()</span>, <span class="string">&quot;110&quot;</span>);</span><br><span class="line">    User user2 = <span class="keyword">new</span> <span class="constructor">User(<span class="string">&quot;张三&quot;</span>, <span class="string">&quot;http:lcoalhost：8080//user.png&quot;</span>, <span class="string">&quot;李四&quot;</span>, <span class="params">new</span> Date()</span>, <span class="string">&quot;110&quot;</span>);</span><br><span class="line">    User user3 = <span class="keyword">new</span> <span class="constructor">User(<span class="string">&quot;张三&quot;</span>, <span class="string">&quot;http:lcoalhost：8080//user.png&quot;</span>, <span class="string">&quot;李四&quot;</span>, <span class="params">new</span> Date()</span>, <span class="string">&quot;110&quot;</span>);</span><br><span class="line">    User user4 = <span class="keyword">new</span> <span class="constructor">User(<span class="string">&quot;张三&quot;</span>, <span class="string">&quot;http:lcoalhost：8080//user.png&quot;</span>, <span class="string">&quot;李四&quot;</span>, <span class="params">new</span> Date()</span>, <span class="string">&quot;110&quot;</span>);</span><br><span class="line">    users.add(user1);</span><br><span class="line">    users.add(user2);</span><br><span class="line">    users.add(user3);</span><br><span class="line">    users.add(user4);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> (User user : users) &#123;</span><br><span class="line">        Map&lt;String, Object&gt; map = <span class="keyword">new</span> LinkedHashMap&lt;&gt;<span class="literal">()</span>;</span><br><span class="line">        <span class="comment">//filed 属性</span></span><br><span class="line">        <span class="keyword">for</span> (Field field : user.get<span class="constructor">Class()</span>.get<span class="constructor">DeclaredFields()</span>) &#123;</span><br><span class="line">            field.set<span class="constructor">Accessible(<span class="params">true</span>)</span>;</span><br><span class="line">            map.put(field.get<span class="constructor">Name()</span> ,field.get<span class="constructor">Type()</span>.equals(<span class="module-access"><span class="module"><span class="identifier">Map</span>.</span></span><span class="keyword">class</span>)<span class="operator"> || </span>field.get<span class="constructor">Type()</span>.equals(<span class="module-access"><span class="module"><span class="identifier">List</span>.</span></span><span class="keyword">class</span>) ? gson.<span class="keyword">to</span><span class="constructor">Json(<span class="params">field</span>.<span class="params">get</span>(<span class="params">user</span>)</span>)  : field.get(user));</span><br><span class="line">        &#125;</span><br><span class="line">        csvWriter.write(map, headers);</span><br><span class="line">    &#125;</span><br><span class="line">    csvWriter.close<span class="literal">()</span>;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="SpringBoot生成二维码"><a href="#SpringBoot生成二维码" class="headerlink" title="SpringBoot生成二维码"></a>SpringBoot生成二维码</h2><h3 id="导入依赖"><a href="#导入依赖" class="headerlink" title="导入依赖"></a>导入依赖</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 二维码 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.google.zxing<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>javase<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.3.3<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="编写工具类"><a href="#编写工具类" class="headerlink" title="编写工具类"></a>编写工具类</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> xyz.dongzi.dzchat.util;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.google.zxing.*;</span><br><span class="line"><span class="keyword">import</span> com.google.zxing.client.j2se.BufferedImageLuminanceSource;</span><br><span class="line"><span class="keyword">import</span> com.google.zxing.client.j2se.MatrixToImageWriter;</span><br><span class="line"><span class="keyword">import</span> com.google.zxing.common.BitMatrix;</span><br><span class="line"><span class="keyword">import</span> com.google.zxing.common.HybridBinarizer;</span><br><span class="line"><span class="keyword">import</span> com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.imageio.ImageIO;</span><br><span class="line"><span class="keyword">import</span> java.awt.image.BufferedImage;</span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.nio.file.Path;</span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@ClassName</span>: QRCodeUtils</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span>: TODO</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span>: ALin</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span>: 2020/3/31 上午9:26</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">QRCodeUtils</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">createQRCode</span><span class="params">(String filePath, String content)</span> &#123;</span><br><span class="line">        <span class="type">int</span> <span class="variable">width</span> <span class="operator">=</span> <span class="number">300</span>;            <span class="comment">//图片的宽度</span></span><br><span class="line">        <span class="type">int</span> <span class="variable">height</span> <span class="operator">=</span> <span class="number">300</span>;            <span class="comment">//图片的高度</span></span><br><span class="line">        <span class="type">String</span> <span class="variable">format</span> <span class="operator">=</span> <span class="string">&quot;png&quot;</span>;        <span class="comment">//图片的格式</span></span><br><span class="line"><span class="comment">//        String content=&quot;风间影月&quot;;     //内容</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 定义二维码的参数</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">HashMap</span> <span class="variable">hints</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">HashMap</span>();</span><br><span class="line">        hints.put(EncodeHintType.CHARACTER_SET, <span class="string">&quot;utf-8&quot;</span>);    <span class="comment">//指定字符编码为“utf-8”</span></span><br><span class="line">        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);  <span class="comment">//指定二维码的纠错等级为中级</span></span><br><span class="line">        hints.put(EncodeHintType.MARGIN, <span class="number">2</span>);    <span class="comment">//设置图片的边距</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 生成二维码</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="type">BitMatrix</span> <span class="variable">bitMatrix</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MultiFormatWriter</span>().encode(content, BarcodeFormat.QR_CODE, width, height, hints);</span><br><span class="line">            <span class="type">Path</span> <span class="variable">file</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(filePath).toPath();</span><br><span class="line">            MatrixToImageWriter.writeToPath(bitMatrix, format, file);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">getContentFromQRCode</span><span class="params">(String filePath)</span> &#123;</span><br><span class="line">        <span class="type">MultiFormatReader</span> <span class="variable">formatReader</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MultiFormatReader</span>();</span><br><span class="line">        <span class="type">File</span> <span class="variable">file</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(filePath);</span><br><span class="line">        BufferedImage image;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            image = ImageIO.read(file);</span><br><span class="line">            <span class="type">BinaryBitmap</span> <span class="variable">binaryBitmap</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">BinaryBitmap</span>(<span class="keyword">new</span> <span class="title class_">HybridBinarizer</span></span><br><span class="line">                    (<span class="keyword">new</span> <span class="title class_">BufferedImageLuminanceSource</span>(image)));</span><br><span class="line">            <span class="type">HashMap</span> <span class="variable">hints</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">HashMap</span>();</span><br><span class="line">            hints.put(EncodeHintType.CHARACTER_SET, <span class="string">&quot;utf-8&quot;</span>);    <span class="comment">//指定字符编码为“utf-8”</span></span><br><span class="line">            <span class="type">Result</span> <span class="variable">result</span> <span class="operator">=</span> formatReader.decode(binaryBitmap, hints);</span><br><span class="line">            <span class="keyword">return</span> result.toString();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="测试-1"><a href="#测试-1" class="headerlink" title="测试"></a>测试</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">void</span> <span class="title function_">contextLoads</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">QRCodeUtils</span> <span class="variable">qrCodeUtils</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">QRCodeUtils</span>();</span><br><span class="line">    qrCodeUtils.createQRCode(<span class="string">&quot;D:\\桌面\\东子.png&quot;</span>,<span class="string">&quot;东子东子东子东子，好帅啊&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="七牛云整合SpringBoot"><a href="#七牛云整合SpringBoot" class="headerlink" title="七牛云整合SpringBoot"></a>七牛云整合SpringBoot</h2><h3 id="配置文件"><a href="#配置文件" class="headerlink" title="配置文件"></a>配置文件</h3><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 七牛云</span></span><br><span class="line"><span class="attr">qiniu:</span></span><br><span class="line">  <span class="attr">accessKey:</span> <span class="string">WUSEs3pLabGERLr1Gr4HFhM0r-uK8r0B_aZC35xl</span> <span class="comment"># 密钥部分</span></span><br><span class="line">  <span class="attr">secretKey:</span> <span class="string">RKTpIO_Klf2fXa6CHZjf1PA_bgtrTyE_Yd1noo9k</span></span><br><span class="line">  <span class="attr">bucketName:</span> <span class="string">helloworld1314</span> <span class="comment"># 空间名字</span></span><br><span class="line">  <span class="attr">path:</span> <span class="string">r9nppu57j.hn-bkt.clouddn.com</span> <span class="comment">#域名</span></span><br></pre></td></tr></table></figure>

<h3 id="引入依赖"><a href="#引入依赖" class="headerlink" title="引入依赖"></a>引入依赖</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 七牛云 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.qiniu<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>qiniu-java-sdk<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>[7.7.0, 7.7.99]<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="编写config配置类"><a href="#编写config配置类" class="headerlink" title="编写config配置类"></a>编写config配置类</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> xyz.dongzi.content.configure;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.qiniu.storage.Configuration;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.storage.UploadManager;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.util.Auth;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Value;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Bean;</span><br><span class="line"></span><br><span class="line"><span class="meta">@org</span>.springframework.context.annotation.Configuration</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UploadConfig</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;qiniu.accessKey&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> String accessKey;</span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;qiniu.secretKey&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> String secretKey;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 认证</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="keyword">public</span> Auth <span class="title function_">getAuth</span><span class="params">()</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> Auth.create(accessKey,secretKey);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 得到上传管理器</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="keyword">public</span> UploadManager <span class="title function_">getUploadManager</span><span class="params">()</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">UploadManager</span>(<span class="keyword">new</span> <span class="title class_">Configuration</span>());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="编写七牛云util"><a href="#编写七牛云util" class="headerlink" title="编写七牛云util"></a>编写七牛云util</h3><figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> xyz.dongzi.content.util;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.qiniu.common.QiniuException;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.http.Response;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.storage.UploadManager;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.util.Auth;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.<span class="keyword">annotation</span>.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.<span class="keyword">annotation</span>.Value;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.FileInputStream;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">QiniuUtils</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> UploadManager uploadManager;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> Auth auth;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Value(<span class="string">&quot;<span class="subst">$&#123;qiniu.bucketName&#125;</span>&quot;</span>)</span></span><br><span class="line">    <span class="keyword">private</span> String bucketName;</span><br><span class="line">    <span class="meta">@Value(<span class="string">&quot;<span class="subst">$&#123;qiniu.path&#125;</span>&quot;</span>)</span></span><br><span class="line">    <span class="keyword">private</span> String url;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> String upload(FileInputStream file, String fileName) throws QiniuException &#123;</span><br><span class="line">        String token = auth.uploadToken(bucketName);</span><br><span class="line">        Response res = uploadManager.put(file, fileName, token, <span class="literal">null</span>, <span class="literal">null</span>);</span><br><span class="line">        <span class="keyword">if</span> (!res.isOK()) &#123;</span><br><span class="line">            <span class="keyword">throw</span> new RuntimeException(<span class="string">&quot;上传七牛云出错:&quot;</span> + res);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> url+<span class="string">&quot;/&quot;</span>+fileName;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="防止图片重名的工具类"><a href="#防止图片重名的工具类" class="headerlink" title="防止图片重名的工具类"></a>防止图片重名的工具类</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> xyz.dongzi.content.util;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.UUID;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">StringUtils</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@Description</span>: 生成唯一图片名称</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@Param</span>: fileName</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span>: 云服务器fileName</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">getRandomImgName</span><span class="params">(String fileName)</span> &#123;</span><br><span class="line"></span><br><span class="line">        <span class="type">int</span> <span class="variable">index</span> <span class="operator">=</span> fileName.lastIndexOf(<span class="string">&quot;.&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (fileName.isEmpty() || index == -<span class="number">1</span>)&#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">IllegalArgumentException</span>();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 获取文件后缀</span></span><br><span class="line">        <span class="type">String</span> <span class="variable">suffix</span> <span class="operator">=</span> fileName.substring(index).toLowerCase();</span><br><span class="line">        <span class="comment">// 生成UUID</span></span><br><span class="line">        <span class="type">String</span> <span class="variable">uuid</span> <span class="operator">=</span> UUID.randomUUID().toString().replaceAll(<span class="string">&quot;-&quot;</span>, <span class="string">&quot;&quot;</span>);</span><br><span class="line">        <span class="comment">// 生成上传至云服务器的路径</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;userAvatar:&quot;</span> + uuid + suffix;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="controller"><a href="#controller" class="headerlink" title="controller"></a>controller</h3><figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">@RestController</span></span><br><span class="line">public class PictureController &#123;</span><br><span class="line">    </span><br><span class="line">    <span class="variable">@Autowired</span></span><br><span class="line">    private PictureService pictureService;</span><br><span class="line"></span><br><span class="line">    <span class="variable">@PostMapping</span>(value = <span class="string">&quot;/upload&quot;</span>)</span><br><span class="line">    public Result&lt;String&gt; <span class="built_in">upload</span>(<span class="variable">@RequestParam</span>(<span class="string">&quot;file&quot;</span>) MultipartFile file) &#123;</span><br><span class="line">        <span class="selector-tag">return</span> <span class="selector-tag">pictureService</span><span class="selector-class">.upload</span>(file);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Service"><a href="#Service" class="headerlink" title="Service"></a>Service</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> xyz.dongzi.content.service.impl;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Service;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.multipart.MultipartFile;</span><br><span class="line"><span class="keyword">import</span> xyz.dongzi.content.service.PictureService;</span><br><span class="line"><span class="keyword">import</span> xyz.dongzi.content.util.QiniuUtils;</span><br><span class="line"><span class="keyword">import</span> xyz.dongzi.content.util.StringUtils;</span><br><span class="line"><span class="keyword">import</span> xyz.dongzi.content.vo.Result;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.FileInputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.util.Objects;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">PictureServiceImpl</span> <span class="keyword">implements</span> <span class="title class_">PictureService</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> QiniuUtils qiniuUtils;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> Result&lt;String&gt; <span class="title function_">upload</span><span class="params">(MultipartFile file)</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (file.isEmpty()) &#123;</span><br><span class="line">            <span class="keyword">return</span> Result.fail(<span class="string">&quot;上传文件为空&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="type">String</span> <span class="variable">fileName</span> <span class="operator">=</span> StringUtils.getRandomImgName(Objects.requireNonNull(file.getOriginalFilename()));</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="type">FileInputStream</span> <span class="variable">uploadFile</span> <span class="operator">=</span> (FileInputStream) file.getInputStream();</span><br><span class="line">            <span class="type">String</span> <span class="variable">path</span> <span class="operator">=</span> qiniuUtils.upload(uploadFile, fileName);</span><br><span class="line">            <span class="comment">/**</span></span><br><span class="line"><span class="comment">             * 成功后返回图片地址</span></span><br><span class="line"><span class="comment">             */</span></span><br><span class="line">            <span class="keyword">return</span> Result.success(path);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">            <span class="keyword">return</span> Result.fail(<span class="string">&quot;失败&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="修改springboot-文件限制"><a href="#修改springboot-文件限制" class="headerlink" title="修改springboot 文件限制"></a>修改springboot 文件限制</h3><figure class="highlight fortran"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 设置文件上传限制</span><br><span class="line">servlet:</span><br><span class="line">  multipart:</span><br><span class="line">    <span class="built_in">max</span>-<span class="keyword">file</span>-<span class="built_in">size</span>: <span class="number">100</span>MB</span><br><span class="line">    <span class="built_in">max</span>-request-<span class="built_in">size</span>: <span class="number">100</span>MB</span><br></pre></td></tr></table></figure>

<h2 id="分页查询mybatisplus"><a href="#分页查询mybatisplus" class="headerlink" title="分页查询mybatisplus"></a>分页查询mybatisplus</h2><h3 id="1-配置分页插件"><a href="#1-配置分页插件" class="headerlink" title="1.配置分页插件"></a>1.配置分页插件</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableTransactionManagement</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">mybatisplusConfig</span> &#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 新分页插件</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="keyword">public</span> MybatisPlusInterceptor <span class="title function_">mybatisPlusInterceptor</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="type">MybatisPlusInterceptor</span> <span class="variable">interceptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MybatisPlusInterceptor</span>();</span><br><span class="line">        interceptor.addInnerInterceptor(<span class="keyword">new</span> <span class="title class_">PaginationInnerInterceptor</span>(DbType.H2));</span><br><span class="line">        <span class="keyword">return</span> interceptor;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2-写controller"><a href="#2-写controller" class="headerlink" title="2.写controller"></a>2.写controller</h3><figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">@<span class="constructor">GetMapping(<span class="string">&quot;/pages&quot;</span>)</span></span><br><span class="line">public Page&lt;Content&gt; get<span class="constructor">Pages(<span class="params">int</span> <span class="params">currentPage</span>,<span class="params">int</span> PageSize)</span>&#123;</span><br><span class="line">    Page&lt;Content&gt; page1 = <span class="keyword">new</span> Page&lt;&gt;(currentPage, PageSize);</span><br><span class="line">    return contentService.find<span class="constructor">Page(<span class="params">page1</span>)</span>;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="3-写service接口"><a href="#3-写service接口" class="headerlink" title="3.写service接口"></a>3.写service接口</h3><figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="type">Page</span>&lt;<span class="type">Content</span>&gt; findPage(<span class="type">Page</span>&lt;<span class="type">Content</span>&gt; page1) &#123;</span><br><span class="line">    <span class="type">Page</span>&lt;<span class="type">Content</span>&gt; pages <span class="operator">=</span> contentdao.selectPage(page1, null);</span><br><span class="line">    <span class="keyword">return</span> pages;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="SpringBoot修改banner"><a href="#SpringBoot修改banner" class="headerlink" title="SpringBoot修改banner"></a>SpringBoot修改banner</h2><ul>
<li>把自己的图片放在classpath路径下面（主要是方便寻找）.</li>
</ul>
<p><img   class="lazyload" data-original="https://gitee.com/yuan-wendong/picture-bed/raw/master/image-20220311222843979.png" src=""  alt="image-20220311222843979"></p>
<ul>
<li>修改application.yml为下面的内容。</li>
</ul>
<p><img   class="lazyload" data-original="https://gitee.com/yuan-wendong/picture-bed/raw/master/image-20220311223017100.png" src=""  alt="image-20220311223017100"></p>
<h2 id="Http请求工具类"><a href="#Http请求工具类" class="headerlink" title="Http请求工具类"></a>Http请求工具类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.apache.http.HttpEntity;</span><br><span class="line"><span class="keyword">import</span> org.apache.http.HttpResponse;</span><br><span class="line"><span class="keyword">import</span> org.apache.http.client.config.RequestConfig;</span><br><span class="line"><span class="keyword">import</span> org.apache.http.client.methods.CloseableHttpResponse;</span><br><span class="line"><span class="keyword">import</span> org.apache.http.client.methods.HttpGet;</span><br><span class="line"><span class="keyword">import</span> org.apache.http.client.methods.HttpPost;</span><br><span class="line"><span class="keyword">import</span> org.apache.http.entity.StringEntity;</span><br><span class="line"><span class="keyword">import</span> org.apache.http.impl.client.CloseableHttpClient;</span><br><span class="line"><span class="keyword">import</span> org.apache.http.impl.client.HttpClients;</span><br><span class="line"><span class="keyword">import</span> org.apache.http.impl.conn.PoolingHttpClientConnectionManager;</span><br><span class="line"><span class="keyword">import</span> org.apache.http.util.EntityUtils;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.BufferedReader;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStreamReader;</span><br><span class="line"><span class="keyword">import</span> java.nio.charset.Charset;</span><br><span class="line"><span class="keyword">import</span> java.nio.charset.StandardCharsets;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> yinfeng</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> http工具类</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@since</span> 2021/12/23 23:21</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">HttpUtil</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> CloseableHttpClient HTTP_CLIENT;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">static</span> &#123;</span><br><span class="line">        <span class="type">PoolingHttpClientConnectionManager</span> <span class="variable">cm</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">PoolingHttpClientConnectionManager</span>();</span><br><span class="line">        cm.setMaxTotal(<span class="number">100</span>);</span><br><span class="line">        cm.setDefaultMaxPerRoute(<span class="number">20</span>);</span><br><span class="line">        cm.setDefaultMaxPerRoute(<span class="number">50</span>);</span><br><span class="line">        HTTP_CLIENT = HttpClients.custom().setConnectionManager(cm).build();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">get</span><span class="params">(String url)</span> &#123;</span><br><span class="line">        <span class="type">CloseableHttpResponse</span> <span class="variable">response</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        BufferedReader in;</span><br><span class="line">        <span class="type">String</span> <span class="variable">result</span> <span class="operator">=</span> <span class="string">&quot;&quot;</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="type">HttpGet</span> <span class="variable">httpGet</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">HttpGet</span>(url);</span><br><span class="line">            <span class="type">RequestConfig</span> <span class="variable">requestConfig</span> <span class="operator">=</span> RequestConfig.custom().setConnectTimeout(<span class="number">30000</span>).setConnectionRequestTimeout(<span class="number">30000</span>).setSocketTimeout(<span class="number">30000</span>).build();</span><br><span class="line">            httpGet.setConfig(requestConfig);</span><br><span class="line">            httpGet.setConfig(requestConfig);</span><br><span class="line">            httpGet.addHeader(<span class="string">&quot;Content-type&quot;</span>, <span class="string">&quot;application/json; charset=utf-8&quot;</span>);</span><br><span class="line">            httpGet.setHeader(<span class="string">&quot;Accept&quot;</span>, <span class="string">&quot;application/json&quot;</span>);</span><br><span class="line">            response = HTTP_CLIENT.execute(httpGet);</span><br><span class="line">            in = <span class="keyword">new</span> <span class="title class_">BufferedReader</span>(<span class="keyword">new</span> <span class="title class_">InputStreamReader</span>(response.getEntity().getContent()));</span><br><span class="line">            <span class="type">StringBuilder</span> <span class="variable">sb</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StringBuilder</span>(<span class="string">&quot;&quot;</span>);</span><br><span class="line">            String line;</span><br><span class="line">            <span class="type">String</span> <span class="variable">nL</span> <span class="operator">=</span> System.getProperty(<span class="string">&quot;line.separator&quot;</span>);</span><br><span class="line">            <span class="keyword">while</span> ((line = in.readLine()) != <span class="literal">null</span>) &#123;</span><br><span class="line">                sb.append(line).append(nL);</span><br><span class="line">            &#125;</span><br><span class="line">            in.close();</span><br><span class="line">            result = sb.toString();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                <span class="keyword">if</span> (<span class="literal">null</span> != response) &#123;</span><br><span class="line">                    response.close();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> result;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">post</span><span class="params">(String url, String jsonString)</span> &#123;</span><br><span class="line">        <span class="type">HttpPost</span> <span class="variable">httpPost</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">HttpPost</span>(url);</span><br><span class="line">        <span class="type">CloseableHttpClient</span> <span class="variable">client</span> <span class="operator">=</span> HttpClients.createDefault();</span><br><span class="line">        <span class="comment">//解决中文乱码问题</span></span><br><span class="line">        <span class="type">StringEntity</span> <span class="variable">entity</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StringEntity</span>(jsonString, <span class="string">&quot;utf-8&quot;</span>);</span><br><span class="line">        entity.setContentEncoding(<span class="string">&quot;utf-8&quot;</span>);</span><br><span class="line">        entity.setContentType(<span class="string">&quot;application/json&quot;</span>);</span><br><span class="line">        httpPost.setEntity(entity);</span><br><span class="line">        HttpResponse response;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            response = client.execute(httpPost);</span><br><span class="line">            <span class="keyword">if</span>(response.getStatusLine().getStatusCode() == <span class="number">200</span>)&#123;</span><br><span class="line">                <span class="type">HttpEntity</span> <span class="variable">httpEntity</span> <span class="operator">=</span> response.getEntity();</span><br><span class="line">                <span class="keyword">return</span> EntityUtils.toString(httpEntity, <span class="string">&quot;utf-8&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="SpringBoot整合JavaMail发送邮件"><a href="#SpringBoot整合JavaMail发送邮件" class="headerlink" title="SpringBoot整合JavaMail发送邮件"></a>SpringBoot整合JavaMail发送邮件</h2><h3 id="发送普通邮件"><a href="#发送普通邮件" class="headerlink" title="发送普通邮件"></a>发送普通邮件</h3><p><strong>导入坐标</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>

<p><strong>配置账号密码邮箱</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">spring:</span><br><span class="line">  mail:</span><br><span class="line">    host: smtp.qq.com</span><br><span class="line">    username: 2911890696@qq.com</span><br><span class="line">    password: phfksjtyrqnldfff</span><br></pre></td></tr></table></figure>

<p><strong>service以及实现</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">package com.example.mergersomethingpro.service;</span><br><span class="line"></span><br><span class="line">public interface SendmailService &#123;</span><br><span class="line">    public void sendmail();</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">package com.example.mergersomethingpro.service.serviceimpl;</span><br><span class="line"></span><br><span class="line">import com.example.mergersomethingpro.service.SendmailService;</span><br><span class="line">import org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line">import org.springframework.mail.SimpleMailMessage;</span><br><span class="line">import org.springframework.mail.javamail.JavaMailSender;</span><br><span class="line">import org.springframework.stereotype.Service;</span><br><span class="line"></span><br><span class="line">@Service</span><br><span class="line">public class Sendserviceimpl implements SendmailService &#123;</span><br><span class="line">    private String from = &quot;2911890696@qq.com&quot;;</span><br><span class="line">    private String to = &quot;y18228735128@163.com&quot;;</span><br><span class="line">    private String title = &quot;标题&quot;;</span><br><span class="line">    private String text = &quot;消息的正文内容&quot;;</span><br><span class="line"></span><br><span class="line">    @Autowired</span><br><span class="line">    private JavaMailSender mailsender;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void sendmail() &#123;</span><br><span class="line">        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();</span><br><span class="line">        simpleMailMessage.setFrom(from);</span><br><span class="line">        simpleMailMessage.setTo(to);</span><br><span class="line">        simpleMailMessage.setSubject(title);</span><br><span class="line">        simpleMailMessage.setText(text);</span><br><span class="line"></span><br><span class="line">        mailsender.send(simpleMailMessage);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>测试</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">@SpringBootTest</span><br><span class="line">class MergerSomethingProApplicationTests &#123;</span><br><span class="line">    @Autowired</span><br><span class="line">    private Sendserviceimpl mailsender;</span><br><span class="line"></span><br><span class="line">    @Test</span><br><span class="line">    void contextLoads() &#123;</span><br><span class="line">        mailsender.sendmail();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="发送复杂邮件（html-图片…"><a href="#发送复杂邮件（html-图片…" class="headerlink" title="发送复杂邮件（html 图片…)"></a>发送复杂邮件（html 图片…)</h3><p><strong>发送html格式，以及发送附件</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">//发送复杂邮件</span><br><span class="line">@Autowired</span><br><span class="line">private JavaMailSender javaMailSender;</span><br><span class="line">private String from1 = &quot;2911890696@qq.com&quot;;</span><br><span class="line">private String to1= &quot;y18228735128@163.com&quot;;</span><br><span class="line">private String title1 = &quot;send complex mail&quot;;</span><br><span class="line">private String text1 = &quot;hello wrold\\n&lt;img src =&#x27;https://tse1-mm.cn.bing.net/th/id/R-C.4d9cd2e53dddfc238a06e750b73cd023?rik=MsMCKPGumufOyQ&amp;riu=http%3a%2f%2fwww.desktx.com%2fd%2ffile%2fwallpaper%2fscenery%2f20170209%2fc2accfe637f86fb6f11949cb8651a09b.jpg&amp;ehk=ia2TVXcow6ygWUVZ1yod5xH4aGd8565SYn6CRpxkNoo%3d&amp;risl=&amp;pid=ImgRaw&amp;r=0&#x27; &gt;&quot;;</span><br><span class="line"></span><br><span class="line">@Override</span><br><span class="line">public void sendComplexMail() &#123;</span><br><span class="line">    MimeMessage mimeMessage = javaMailSender.createMimeMessage();</span><br><span class="line">    try &#123;</span><br><span class="line">        MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage,true); //true represent Attachment</span><br><span class="line">        mimeMessageHelper.setFrom(from1);</span><br><span class="line">        mimeMessageHelper.setTo(to1);</span><br><span class="line">        mimeMessageHelper.setSubject(title1);</span><br><span class="line">        mimeMessageHelper.setText(text1,true);//true表示可以使用html语法</span><br><span class="line">        File file = new File(&quot;D:\\桌面\\演员.mp3&quot;);</span><br><span class="line">        mimeMessageHelper.addAttachment(file.getName(),file);</span><br><span class="line">        javaMailSender.send(mimeMessage);</span><br><span class="line">        System.out.println(&quot;success&quot;);</span><br><span class="line"></span><br><span class="line">    &#125; catch (Exception e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>注意</strong></p>
<p>这里的主要变化为</p>
<p><code>            MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage,true);</code></p>
<p>MIme消息后面的那个true参数，代表发送附件（发送htm不用这样）</p>
<p>以及<code>mimeMessageHelper.setText(text1,true);</code></p>
<p>true表示可以使用html语法</p>
<h2 id="定时任务"><a href="#定时任务" class="headerlink" title="定时任务"></a>定时任务</h2><h3 id="quartz的坐标"><a href="#quartz的坐标" class="headerlink" title="quartz的坐标"></a>quartz的坐标</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-quartz<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="任务"><a href="#任务" class="headerlink" title="任务"></a>任务</h3><figure class="highlight scala"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.quartz.<span class="type">JobExecutionContext</span>;</span><br><span class="line"><span class="keyword">import</span> org.quartz.<span class="type">JobExecutionException</span>;</span><br><span class="line"><span class="keyword">import</span> org.springframework.scheduling.quartz.<span class="type">QuartzJobBean</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">public <span class="class"><span class="keyword">class</span> <span class="title">Quartz</span>  <span class="keyword">extends</span> <span class="title">QuartzJobBean</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">protected</span> void executeInternal(<span class="type">JobExecutionContext</span> context) <span class="keyword">throws</span> <span class="type">JobExecutionException</span> &#123;</span><br><span class="line">        <span class="type">System</span>.out.println(<span class="string">&quot;hello zhe shi dingshi &quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">import com.example.mergesomething.quartz.Quartz;</span><br><span class="line">import org.quartz.*;</span><br><span class="line">import org.springframework.context.annotation.Bean;</span><br><span class="line">import org.springframework.context.annotation.Configuration;</span><br><span class="line"></span><br><span class="line">@Configuration</span><br><span class="line">public class quartzcobfiguration &#123;</span><br><span class="line">    //joddetail</span><br><span class="line">    @Bean</span><br><span class="line">    public JobDetail myjobdetail()&#123;</span><br><span class="line">        return JobBuilder.newJob(Quartz.class).storeDurably().build();</span><br><span class="line">    &#125;</span><br><span class="line">    //trigger</span><br><span class="line">    @Bean</span><br><span class="line">    public Trigger mytrigger()&#123;</span><br><span class="line">        //crone Exception</span><br><span class="line">        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(&quot;0/1 * * * * ?&quot;);</span><br><span class="line">        //trigger</span><br><span class="line">        return TriggerBuilder.newTrigger().</span><br><span class="line">                forJob(myjobdetail()).</span><br><span class="line">                withSchedule(cronScheduleBuilder).build();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="java-原生实现定时任务"><a href="#java-原生实现定时任务" class="headerlink" title="java 原生实现定时任务"></a>java 原生实现定时任务</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">package com.example.mergesomething;</span><br><span class="line"></span><br><span class="line">import java.util.Date;</span><br><span class="line">import java.util.Timer;</span><br><span class="line">import java.util.TimerTask;</span><br><span class="line"></span><br><span class="line">public class JavaTimer &#123;</span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        Timer timer = new Timer();</span><br><span class="line">        TimerTask task = new TimerTask() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public void run() &#123;</span><br><span class="line">                System.out.println(&quot;hello world&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line">//        timer.schedule(task,0,2000);</span><br><span class="line">        timer.schedule(task,new Date(),2);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="git初始化仓库"><a href="#git初始化仓库" class="headerlink" title="git初始化仓库"></a>git初始化仓库</h3><ul>
<li>git init</li>
<li>git add.</li>
<li>git commit -m”第一次提交”</li>
<li>git remote add origin <a target="_blank" rel="noopener" href="https://gitee.com/yuan-wendong/robot.git">https://gitee.com/yuan-wendong/robot.git</a></li>
<li>[切换分支]git checkout -b ywd </li>
<li>git push -u origin ywd</li>
</ul>
<h2 id="Mybatis-x2F-MybatisPlus"><a href="#Mybatis-x2F-MybatisPlus" class="headerlink" title="Mybatis&#x2F;MybatisPlus"></a>Mybatis&#x2F;MybatisPlus</h2><h3 id="批量删除，使用in语句"><a href="#批量删除，使用in语句" class="headerlink" title="批量删除，使用in语句"></a>批量删除，使用in语句</h3><figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">@Delete</span>(<span class="string">&quot;DELETE FROM users WHERE id IN &quot;</span> +</span><br><span class="line">        <span class="string">&quot;&lt;foreach collection=\&quot;</span>ids\<span class="string">&quot; item=\&quot;</span>id\<span class="string">&quot; open=\&quot;</span>(\<span class="string">&quot; separator=\&quot;</span>,\<span class="string">&quot; close=\&quot;</span>)\<span class="string">&quot;&gt;&quot;</span> +</span><br><span class="line">        <span class="string">&quot;#&#123;id&#125;&quot;</span> +</span><br><span class="line">        <span class="string">&quot;&lt;/foreach&gt;&quot;</span>)</span><br><span class="line">void <span class="built_in">deleteUsersByIds</span>(<span class="variable">@Param</span>(<span class="string">&quot;ids&quot;</span>) List&lt;Long&gt; ids);</span><br></pre></td></tr></table></figure>

<h2 id="组内排序"><a href="#组内排序" class="headerlink" title="组内排序"></a>组内排序</h2><p><img   class="lazyload" data-original="https://gitee.com/yuan-wendong/picture-bed/raw/master/image-20230404100342631.png" src=""  alt="image-20230404100342631"></p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span></span><br><span class="line">	* </span><br><span class="line"><span class="keyword">FROM</span></span><br><span class="line">	sys_table_a </span><br><span class="line"><span class="keyword">WHERE</span></span><br><span class="line">	create_time <span class="keyword">IN</span> (</span><br><span class="line">	<span class="keyword">SELECT</span></span><br><span class="line">		max( create_time ) </span><br><span class="line">	<span class="keyword">FROM</span></span><br><span class="line">		(</span><br><span class="line">		<span class="keyword">SELECT</span></span><br><span class="line">			a.id,</span><br><span class="line">			CONVERT ( create_time, <span class="type">CHAR</span> ( <span class="number">10</span> ) ) datetemp,</span><br><span class="line">			a.num,</span><br><span class="line">			a.NAME,</span><br><span class="line">			a.create_time </span><br><span class="line">		<span class="keyword">FROM</span></span><br><span class="line">			sys_table_a <span class="keyword">AS</span> a </span><br><span class="line">		) <span class="keyword">AS</span> aa </span><br><span class="line">	<span class="keyword">GROUP</span> <span class="keyword">BY</span></span><br><span class="line">		aa.datetemp </span><br><span class="line">	) </span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">SELECT</span></span><br><span class="line">	* </span><br><span class="line"><span class="keyword">FROM</span></span><br><span class="line">	(</span><br><span class="line">	<span class="keyword">SELECT</span></span><br><span class="line">		a.id,</span><br><span class="line">		CONVERT ( create_time, <span class="type">CHAR</span> ( <span class="number">10</span> ) ) datetemp,</span><br><span class="line">		a.num,</span><br><span class="line">		a.NAME,</span><br><span class="line">		a.create_time,</span><br><span class="line">		rank ( ) <span class="keyword">over</span> ( <span class="keyword">PARTITION</span> <span class="keyword">BY</span> CONVERT ( create_time, <span class="type">CHAR</span> ( <span class="number">10</span> ) ) <span class="keyword">ORDER</span> <span class="keyword">BY</span> a.create_time <span class="keyword">DESC</span> ) <span class="keyword">AS</span> rk </span><br><span class="line">	<span class="keyword">FROM</span></span><br><span class="line">		sys_table_a <span class="keyword">AS</span> a </span><br><span class="line">	) <span class="keyword">AS</span> b </span><br><span class="line"><span class="keyword">WHERE</span></span><br><span class="line">	b.rk = <span class="number">1</span></span><br></pre></td></tr></table></figure>

<h2 id="几张图片合并为一张长图"><a href="#几张图片合并为一张长图" class="headerlink" title="几张图片合并为一张长图"></a>几张图片合并为一张长图</h2><figure class="highlight arduino"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cn.hutool.core.img.ImgUtil;</span><br><span class="line"><span class="keyword">import</span> cn.hutool.core.io.IoUtil;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.awt.image.BufferedImage;</span><br><span class="line"><span class="keyword">import</span> java.io.*;</span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="type">static</span> net.sf.jsqlparser.parser.feature.Feature.merge;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @author thon</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ImgUtils</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="type">static</span> <span class="type">void</span> <span class="title">merge</span><span class="params">(List&lt;<span class="type">byte</span>[]&gt; pngList, <span class="type">String</span> imageType, OutputStream outputStream)</span></span>&#123;</span><br><span class="line">        <span class="type">int</span> destHeight = <span class="number">0</span>;</span><br><span class="line">        <span class="type">int</span> destWidth = <span class="number">0</span>;</span><br><span class="line">        <span class="type">int</span> len = pngList.<span class="built_in">size</span>();</span><br><span class="line"></span><br><span class="line">        BufferedImage[] images = <span class="keyword">new</span> BufferedImage[len];</span><br><span class="line">        <span class="type">int</span>[][] imageArrays = <span class="keyword">new</span> <span class="type">int</span>[len][];</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i &lt; len; i++) &#123;</span><br><span class="line">            images[i] = ImgUtil.<span class="built_in">toImage</span>(pngList.<span class="built_in">get</span>(i));</span><br><span class="line">            <span class="type">int</span> width = images[i].<span class="built_in">getWidth</span>();</span><br><span class="line">            <span class="type">int</span> height = images[i].<span class="built_in">getHeight</span>();</span><br><span class="line"></span><br><span class="line">            imageArrays[i] = <span class="keyword">new</span> <span class="type">int</span>[width * height];</span><br><span class="line">            imageArrays[i] = images[i].<span class="built_in">getRGB</span>(<span class="number">0</span>, <span class="number">0</span>, width, height, imageArrays[i], <span class="number">0</span>, width);</span><br><span class="line"></span><br><span class="line">            destWidth = Math.<span class="built_in">max</span>(destWidth, width);</span><br><span class="line">            destHeight += height;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        BufferedImage img = <span class="keyword">new</span> <span class="built_in">BufferedImage</span>(destWidth, destHeight, BufferedImage.TYPE_INT_RGB);</span><br><span class="line">        <span class="type">int</span> h= <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i &lt; images.length; i++) &#123;</span><br><span class="line">            <span class="type">int</span> width = images[i].<span class="built_in">getWidth</span>();</span><br><span class="line">            <span class="type">int</span> height = images[i].<span class="built_in">getHeight</span>();</span><br><span class="line">            img.<span class="built_in">setRGB</span>(<span class="number">0</span>, h, width, height, imageArrays[i], <span class="number">0</span>, width);</span><br><span class="line">            h += height;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        ImgUtil.<span class="built_in">write</span>(img, imageType, outputStream);</span><br><span class="line">        IoUtil.<span class="built_in">close</span>(outputStream);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>


      </section>
      <section class="extra">
        
          <ul class="copyright">
  
    <li><strong>本文作者：</strong>东子</li>
    <li><strong>本文链接：</strong><a href="https://comebackearly.gitee.io/2018/08/20/%E5%B8%B8%E7%94%A8%E4%BB%A3%E7%A0%81/index.html" title="https:&#x2F;&#x2F;comebackearly.gitee.io&#x2F;2018&#x2F;08&#x2F;20&#x2F;%E5%B8%B8%E7%94%A8%E4%BB%A3%E7%A0%81&#x2F;index.html">https:&#x2F;&#x2F;comebackearly.gitee.io&#x2F;2018&#x2F;08&#x2F;20&#x2F;%E5%B8%B8%E7%94%A8%E4%BB%A3%E7%A0%81&#x2F;index.html</a></li>
    <li><strong>版权声明：</strong>本博客所有文章均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" title="BY-NC-SA" target="_blank" rel="noopener">BY-NC-SA</a> 许可协议，转载请注明出处！</li>
  
</ul>
        
        
        
        
  <nav class="nav">
    <a href="/2022/06/01/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/"><i class="iconfont iconleft"></i>计算机网络</a>
    <a href="/2018/08/20/POEM/">POEM<i class="iconfont iconright"></i></a>
  </nav>

      </section>
      
        <section class="comments">
  
    <div class="btn" id="comments-btn">查看评论</div>
  
  
<div id="valine"></div>
<script defer src="//unpkg.com/valine/dist/Valine.min.js"></script>
<script>
  window.onload = function () {
    var loadValine = function () {
      new Valine({
        el: '#valine',
        app_id: "833C0IwLe9o8QE1pN25Mv59F-gzGzoHsz",
        app_key: "YLQZdn7egrZOmJnwr6YFEw0y",
        placeholder: "雁过留痕",
        avatar: "mp",
        pageSize: "10",
        lang: "zh-CN",
      });
    }
    if ( true ) {
      $("#comments-btn").on("click", function () {
        $(this).hide();
        loadValine();
      });
    } else {
      loadValine();
    }
  };
</script>

</section>
      
    </section>
  </div>
</article></div>
      <div class="col-xl-3">
        
          
  <aside class="toc-wrap">
    <h3 class="toc-title">文章目录：</h3>
    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81"><span class="toc-text">代码</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AEtomcat%E8%99%9A%E6%8B%9F%E7%9B%AE%E5%BD%95"><span class="toc-text">设置tomcat虚拟目录</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BD%93%E7%BB%93%E6%9E%9C%E4%B8%8D%E4%B8%BA%E7%A9%BA%E6%97%B6%E5%80%99%E5%B0%81%E8%A3%85%E4%B8%BAjson%E8%BF%94%E5%9B%9E"><span class="toc-text">当结果不为空时候封装为json返回</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BF%AB%E9%80%9F%E5%A4%8D%E5%88%B6%E4%B8%80%E4%B8%AA%E6%96%87%E4%BB%B6%E5%88%B0%E5%8F%A6%E4%B8%80%E4%B8%AA%E6%96%87%E4%BB%B6"><span class="toc-text">快速复制一个文件到另一个文件</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Blog"><span class="toc-text">Blog</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BC%98%E9%9B%85%E4%BB%A3%E7%A0%81%E2%80%94%E2%80%94-%E6%9E%84%E5%BB%BA%E7%9B%AE%E5%BD%95%E6%A0%91%EF%BC%88%E7%94%A8%E5%8A%A8%E6%80%81%E8%8F%9C%E5%8D%95%E4%B8%BE%E4%BE%8B%E5%AD%90%EF%BC%89"><span class="toc-text">优雅代码——-构建目录树（用动态菜单举例子）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#PageVO"><span class="toc-text">PageVO</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95%E7%A5%9E%E5%99%A8"><span class="toc-text">测试神器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#aop%E6%B3%A8%E8%A7%A3%E6%97%A5%E5%BF%97"><span class="toc-text">aop注解日志</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%BC%80%E5%8F%91%E5%B8%B8%E7%94%A8%E5%8A%9F%E8%83%BD"><span class="toc-text">开发常用功能</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringBoot%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B3%A8%E8%A7%A3%E6%8B%A6%E6%88%AA%E6%9D%83%E9%99%90"><span class="toc-text">SpringBoot自定义注解拦截权限</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B3%A8%E8%A7%A3"><span class="toc-text">自定义注解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E6%8B%A6%E6%88%AA%E5%99%A8"><span class="toc-text">添加一个拦截器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9C%A8%E9%9C%80%E8%A6%81%E7%9A%84%E6%8E%A5%E5%8F%A3%E4%B8%8A%E6%B7%BB%E5%8A%A0%E6%B3%A8%E8%A7%A3"><span class="toc-text">在需要的接口上添加注解</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%89%B9%E9%87%8F%E4%BF%AE%E6%94%B9%E6%96%87%E4%BB%B6%E5%90%8E%E7%BC%80"><span class="toc-text">批量修改文件后缀</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%88%E6%9E%9C"><span class="toc-text">效果</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81-1"><span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#java%E6%A0%B9%E6%8D%AE%E5%AE%9E%E4%BD%93%E7%B1%BB%E7%94%9F%E6%88%90%E7%9B%B8%E5%BA%94%E7%9A%84%E6%95%B0%E6%8D%AE%E5%BA%93sql%E6%96%87%E4%BB%B6"><span class="toc-text">java根据实体类生成相应的数据库sql文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#java-%E6%89%BE%E5%87%BA%E7%89%B9%E5%AE%9A%E5%90%8E%E7%BC%80%E6%96%87%E4%BB%B6"><span class="toc-text">java 找出特定后缀文件</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9A%E4%B9%89%E8%BF%87%E6%BB%A4%E5%99%A8"><span class="toc-text">定义过滤器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95"><span class="toc-text">测试</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Java%E7%94%9F%E6%88%90%E5%8E%8B%E7%BC%A9%E5%8C%85"><span class="toc-text">Java生成压缩包</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringBoot%E5%AF%BC%E5%87%BAcsv"><span class="toc-text">SpringBoot导出csv</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8A%A0%E5%85%A5%E4%BE%9D%E8%B5%96"><span class="toc-text">加入依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BC%96%E5%86%99controller"><span class="toc-text">编写controller</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BC%96%E5%86%99service"><span class="toc-text">编写service</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringBoot%E7%94%9F%E6%88%90%E4%BA%8C%E7%BB%B4%E7%A0%81"><span class="toc-text">SpringBoot生成二维码</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AF%BC%E5%85%A5%E4%BE%9D%E8%B5%96"><span class="toc-text">导入依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BC%96%E5%86%99%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="toc-text">编写工具类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95-1"><span class="toc-text">测试</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%83%E7%89%9B%E4%BA%91%E6%95%B4%E5%90%88SpringBoot"><span class="toc-text">七牛云整合SpringBoot</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-text">配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BC%95%E5%85%A5%E4%BE%9D%E8%B5%96"><span class="toc-text">引入依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BC%96%E5%86%99config%E9%85%8D%E7%BD%AE%E7%B1%BB"><span class="toc-text">编写config配置类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BC%96%E5%86%99%E4%B8%83%E7%89%9B%E4%BA%91util"><span class="toc-text">编写七牛云util</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%98%B2%E6%AD%A2%E5%9B%BE%E7%89%87%E9%87%8D%E5%90%8D%E7%9A%84%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="toc-text">防止图片重名的工具类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#controller"><span class="toc-text">controller</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Service"><span class="toc-text">Service</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9springboot-%E6%96%87%E4%BB%B6%E9%99%90%E5%88%B6"><span class="toc-text">修改springboot 文件限制</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%86%E9%A1%B5%E6%9F%A5%E8%AF%A2mybatisplus"><span class="toc-text">分页查询mybatisplus</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E9%85%8D%E7%BD%AE%E5%88%86%E9%A1%B5%E6%8F%92%E4%BB%B6"><span class="toc-text">1.配置分页插件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%86%99controller"><span class="toc-text">2.写controller</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E5%86%99service%E6%8E%A5%E5%8F%A3"><span class="toc-text">3.写service接口</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringBoot%E4%BF%AE%E6%94%B9banner"><span class="toc-text">SpringBoot修改banner</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Http%E8%AF%B7%E6%B1%82%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="toc-text">Http请求工具类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringBoot%E6%95%B4%E5%90%88JavaMail%E5%8F%91%E9%80%81%E9%82%AE%E4%BB%B6"><span class="toc-text">SpringBoot整合JavaMail发送邮件</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%91%E9%80%81%E6%99%AE%E9%80%9A%E9%82%AE%E4%BB%B6"><span class="toc-text">发送普通邮件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%91%E9%80%81%E5%A4%8D%E6%9D%82%E9%82%AE%E4%BB%B6%EF%BC%88html-%E5%9B%BE%E7%89%87%E2%80%A6"><span class="toc-text">发送复杂邮件（html 图片…)</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1"><span class="toc-text">定时任务</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#quartz%E7%9A%84%E5%9D%90%E6%A0%87"><span class="toc-text">quartz的坐标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%BB%E5%8A%A1"><span class="toc-text">任务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#java-%E5%8E%9F%E7%94%9F%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1"><span class="toc-text">java 原生实现定时任务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#git%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BB%93%E5%BA%93"><span class="toc-text">git初始化仓库</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Mybatis-x2F-MybatisPlus"><span class="toc-text">Mybatis&#x2F;MybatisPlus</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%89%B9%E9%87%8F%E5%88%A0%E9%99%A4%EF%BC%8C%E4%BD%BF%E7%94%A8in%E8%AF%AD%E5%8F%A5"><span class="toc-text">批量删除，使用in语句</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%84%E5%86%85%E6%8E%92%E5%BA%8F"><span class="toc-text">组内排序</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%87%A0%E5%BC%A0%E5%9B%BE%E7%89%87%E5%90%88%E5%B9%B6%E4%B8%BA%E4%B8%80%E5%BC%A0%E9%95%BF%E5%9B%BE"><span class="toc-text">几张图片合并为一张长图</span></a></li></ol></li></ol>
  </aside>

        
      </div>
    </div>
  </div>
</main>
  

<footer class="footer">
  <div class="footer-social"><a 
        href="tencent://message/?Menu=yes&uin=2911890696 "
        target="_blank"
        class="footer-social-item"
        onMouseOver="this.style.color= '#12B7F5'" 
        onMouseOut="this.style.color='#33333D'">
          <i class="iconfont  iconQQ "></i>
      </a><a 
        href="javascript:; "
        target="_blank"
        class="footer-social-item"
        onMouseOver="this.style.color= '#09BB07'" 
        onMouseOut="this.style.color='#33333D'">
          <i class="iconfont  iconwechat-fill "></i>
      </a><a 
        href="https://github.com/nuban "
        target="_blank"
        class="footer-social-item"
        onMouseOver="this.style.color= '#9f7be1'" 
        onMouseOut="this.style.color='#33333D'">
          <i class="iconfont  icongithub-fill "></i>
      </a></div>
  
    <div class="footer-copyright"><p>Powered by <a target="_blank" href="https://gitee.com/comebackearly">东子</a>  | 爷-青结~~</p></div>
  
  <link rel="stylesheet" href="/dist/APlayer.min.css">
  <div id="aplayer"></div>
  <script type="text/javascript" src="/dist/APlayer.min.js"></script>
  <script type="text/javascript" src="/dist/music.js"></script>
  
</footer>
  
      <div class="fab fab-plus">
    <i class="iconfont iconplus"></i>
  </div>
  
  
  
  <div class="fab fab-up">
    <i class="iconfont iconcaret-up"></i>
  </div>
  
  
  
    
<script src="/js/color-mode.js"></script>

  
  
</body>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>





  
<script src="https://cdn.bootcdn.net/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"></script>




  
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>






  
<script src="https://cdn.bootcdn.net/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>




<script src="/js/utils.js"></script>
<script src="/js/script.js"></script>







  <script>
    (function () {
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
      } else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
      }
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>



  <script defer src='https://hm.baidu.com/hm.js?dda12e485d1b1d3113db8147f482111c'></script>











</html>